package edu.zut.pioneer.staff;


import edu.zut.pioneer.base.controller.GenericController;
import edu.zut.pioneer.sale.domain.Sale;
import edu.zut.pioneer.staff.domain.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/staff",produces = { MediaType.APPLICATION_JSON_VALUE })
public class StaffController extends GenericController<Staff, Long, StaffManager> {
    public static final Logger logger = LogManager.getLogger(StaffController.class.getName());
    StaffManager staffManager;
    @Resource
    public void setAdminManager(StaffManager staffManager){
        this.staffManager=staffManager;
        this.manager=staffManager;
    }
    @RequestMapping(value="/findAll/{page}/{pageSize}",method = {RequestMethod.GET,RequestMethod.POST})
    public Map<String,Object> findAllProduct(@PathVariable("page") int page, @PathVariable("pageSize") int pageSize){
        Sort sort = Sort.by(Sort.Direction.DESC,"id");
        Pageable pageable = PageRequest.of(page,pageSize, sort);
        Page<Staff> list = staffManager.findAll(pageable);
        HashMap<String,Object> map = new HashMap<>();
        map.put("number",list.getTotalElements());
        map.put("userList",list.getContent());
        logger.info("----------->"+list.getContent());
        return map;
    }
}
